package com.hao.tool.extra.cloud.module.wangshang.fac;

import com.hao.tool.common.util.HttpClientUtil;
import com.hao.tool.common.util.JsonKitUtil;
import com.hao.tool.extra.cloud.module.wangshang.dto.DriverScoreDTO;
import com.hao.tool.extra.cloud.module.wangshang.dto.VehicleScoreDTO;
import com.hao.tool.extra.cloud.module.wangshang.res.DriverScoreResult;
import com.hao.tool.extra.cloud.module.wangshang.res.VehicleScoreResult;
import lombok.Getter;
import lombok.Setter;

import java.io.IOException;
import java.util.Map;

/**
 * 网尚
 *
 * @author RuiHaoZ on CMHK.jx
 * @date 2020-07-25 10:18
 */
@Getter
@Setter
public class WSFactory {

    private String authorization;

    public DriverScoreResult execute(String url, DriverScoreDTO scoreDTO) throws IOException {
        String paramsStr = JsonKitUtil.getString(scoreDTO);
        Map<String, String> params = JsonKitUtil.getObject(paramsStr, Map.class);
        String response = HttpClientUtil.build().setLogStatus(true).addHeader("Authorization", authorization)
                .sendGet(url, params);
        DriverScoreResult scoreResult = JsonKitUtil.getObject(response, DriverScoreResult.class);
        return scoreResult;
    }

    public VehicleScoreResult execute(String url, VehicleScoreDTO scoreDTO) throws IOException {
        String paramsStr = JsonKitUtil.getString(scoreDTO);
        Map<String, String> params = JsonKitUtil.getObject(paramsStr, Map.class);
        String response = HttpClientUtil.build().setLogStatus(true).addHeader("Authorization", authorization)
                .sendPost(url, params);
//        response = FileUtil.readString("/Users/haol/Personal/develop/mobile-group/mobile-group-extra/src/main/resources/d2.json", Charset.defaultCharset());
        VehicleScoreResult scoreResult = JsonKitUtil.getObject(response, VehicleScoreResult.class);
        return scoreResult;
    }
}
